<?php

namespace app\model\order;

use app\model\product\product\StoreProduct;
use app\model\product\sku\StoreProductAttrValue;
use app\model\user\User;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

class StoreOrderItem extends BaseModel
{
    use ModelTrait;

    protected $pk = 'id';

    protected $name = 'order_items';

    protected $autoWriteTimestamp = 'int';


    public function mainOrder()
    {
        return $this->belongsTo(StoreOrder::class, 'order_id', 'id');
    }

    public function cart()
    {
        return $this->belongsTo(StoreCart::class, 'cart_id', 'id');
    }

    public function product()
    {
        return $this->belongsTo(StoreProduct::class, 'product_id', 'id');
    }

    public function attrValue()
    {
        return $this->belongsTo(StoreProductAttrValue::class, 'product_attr_value_unique', 'unique');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }
}